20 #include "clock_config.h" 21 #include "fsl_debug_console.h" 26 #include "Driver_I2C.h" 31 #include "issdk_hal.h" 33 #include "gpio_driver.h" 39 #define SDCD_LTHS_LSB 0xA0 40 #define SDCD_LTHS_MSB 0x0F 41 #define SDCD_UTHS_LSB 0x40 42 #define SDCD_UTHS_MSB 0x00 43 #define ASLP_COUNT_LSB 0xFA 44 #define ASLP_COUNT_MSB 0x00 45 #define FXLS8962_DATA_SIZE 6 99 const char *
pActivity[5] = {
"Unknown ",
"Rest ",
"Walking ",
"Jogging ",
"Running "};
110 .bits = {.config = 1},
119 .filtertime = 2, .male = 1,
132 .portPinConfig = {.pullSelect = kPORT_PullUp, .mux = kPORT_MuxAsGpio},
133 .interruptMode = kPORT_InterruptFallingEdge,
165 uint16_t lastReportedSteps;
180 PRINTF(
"\r\n ISSDK FXLS8962 sensor driver example for Motion Activated Pedometer.\r\n");
190 if (ARM_DRIVER_OK != status)
192 PRINTF(
"\r\n I2C Initialization Failed\r\n");
197 status = I2Cdrv->PowerControl(ARM_POWER_FULL);
198 if (ARM_DRIVER_OK != status)
200 PRINTF(
"\r\n I2C Power Mode setting Failed\r\n");
205 status = I2Cdrv->Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_FAST);
206 if (ARM_DRIVER_OK != status)
208 PRINTF(
"\r\n I2C Control Mode setting Failed\r\n");
217 PRINTF(
"\r\n Sensor Initialization Failed\r\n");
226 fxls8962Driver.
slaveAddress, cFxls8962ConfigInitialize);
229 PRINTF(
"\r\n Write FXLS8962 Initialization Failed.\r\n");
235 PRINTF(
"\r\n Pedometer successfully Initialized and Ready for measurements.");
246 PRINTF(
"\r\n Write FXLS8962 Motion Configuration Failed!\r\n");
252 PRINTF(
"\r\n\r\n Waiting for Motion | MCU switching to Sleep Mode ...\r\n");
269 if (ARM_DRIVER_OK != status)
271 PRINTF(
"\r\n Read INT Status Failed!\r\n");
280 PRINTF(
" Motion detected...\r\n");
286 PRINTF(
"\r\n Write FXLS8962 DRDY Configuration Failed.\r\n");
289 motionDetect =
false;
297 if (ARM_DRIVER_OK != status)
299 PRINTF(
"\r\n ERROR : Read Data Failed!\r\n");
304 rawData.
accel[0] = ((int16_t)data[1] << 8) | data[0];
305 rawData.
accel[0] *= 16;
306 rawData.
accel[1] = ((int16_t)data[3] << 8) | data[2];
307 rawData.
accel[1] *= 16;
308 rawData.
accel[2] = ((int16_t)data[5] << 8) | data[4];
309 rawData.
accel[2] *= 16;
321 PRINTF(
"\r\n | Steps | Distance | Speed | Calories | Activity |\r\n");
323 PRINTF(
"\033[K | %5d | %4dm | %2dkmph | %3d | %s |\r",
void(* set_pin)(pinID_t aPinId)
struct pedometer_t::pedometer_status_tag status
#define FXLS8962_INT_EN_DRDY_EN_EN
This structure defines the fxls8962 raw data buffer.
void pedometer_configure(pedometer_t *pPedometer, const pedometer_config_t *pConfig)
The interface function to configure the pedometer.
The GPIO Configuration KSDK.
This structure defines the Write command List.
The pedometer.h file contains the interface and structure definitions for pedometer application...
#define I2C_S_SIGNAL_EVENT
const registerwritelist_t cFxls8962ConfigInitialize[]
FXLS8962 Motion based Pedometer Register Write List.
#define FXLS8962_SENS_CONFIG4_INT_POL_ACT_LOW
status_t SMC_SetPowerModeVlpr(void *arg)
Configures the system to VLPR power mode. API name used from Kinetis family to maintain compatibility...
#define FXLS8962_INT_EN_SDCD_OT_EN_EN
gpioConfigKSDK_t gpioConfigINT1
The fxls8962_drv.h file describes the FXLS8962AF driver interface and structures. ...
#define BOARD_BootClockRUN
int32_t FXLS8962_I2C_Initialize(fxls8962_i2c_sensorhandle_t *pSensorHandle, ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress, uint8_t *whoami)
The interface function to initialize the sensor.
#define FXLS8962_SDCD_CONFIG2_OT_DBCTM_CLEARED
Access structure of the GPIO Driver.
#define FXLS8962_SENS_CONFIG3_SLEEP_ODR_0_781HZ
pedometer_config_t cPedoConfig
This defines the configuration structure of the pedometer.
#define __END_WRITE_DATA__
debounce_count_t sleepcount_threshold
void(* clr_pin)(pinID_t aPinId)
typedef int32_t(DATA_FORMAT_Append_t))(void *pData
The interface function to append the data on the formated stream.
void BOARD_InitDebugConsole(void)
struct pedometer_t::pedometer_status_tag::@351::@352 bits
#define FXLS8962_SENS_CONFIG3_WAKE_ODR_MASK
const registerreadlist_t cFxls8962Output[]
Address of Data Output Registers.
This defines the sensor specific information for I2C.
gpio_pin_config_t pinConfig
#define FXLS8962_SDCD_CONFIG2_SDCD_EN_EN
This defines the pedometer instance.
int32_t Sensor_I2C_Write(ARM_DRIVER_I2C *pCommDrv, registerDeviceInfo_t *devInfo, uint16_t slaveAddress, const registerwritelist_t *pRegWriteList)
Write register data to a sensor.
This defines the acceleration input data for the pedometer.
fxls8962_i2c_sensorhandle_t fxls8962Driver
void(* registeridlefunction_t)(void *userParam)
This is the register idle function type.
GENERIC_DRIVER_GPIO * pGpioDriver
uint8_t data[FXLS8962_DATA_SIZE]
const registerwritelist_t cFxls8962ConfigDataReady[]
FXLS8962 DRDY and ASLP Detect Mode Register Write List.
#define __END_READ_DATA__
#define FXLS8962_DATA_SIZE
const char * pActivity[5]
Pedometer Mode Name Strings.
#define FXLS8962_SENS_CONFIG4_WK_SDCD_OT_MASK
#define FXLS8962_SENS_CONFIG4_WK_SDCD_OT_EN
int32_t FXLS8962_I2C_ReadData(fxls8962_i2c_sensorhandle_t *pSensorHandle, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.
#define FXLS8962_SENS_CONFIG3_WAKE_ODR_50HZ
fxos8700_accelmagdata_t rawData
#define FXLS8962_INT_STATUS_SRC_ASLP_MASK
const registerreadlist_t cFxls8962INTStatus[]
Address of INT Status Register.
#define FXLS8962_SENS_CONFIG4_INT_POL_MASK
#define FXLS8962_SENS_CONFIG3_SLEEP_ODR_MASK
int main(void)
This is the The main function implementation.
const registerwritelist_t cFxls8962ConfigMotionDetect[]
FXLS8962 Motion Detect Mode Register Write List.
ARM_DRIVER_I2C * pCommDrv
void(* toggle_pin)(pinID_t aPinId)
#define FXLS8962_SDCD_CONFIG1_X_OT_EN_EN
int32_t FXLS8962_I2C_Configure(fxls8962_i2c_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList)
The interface function to configure he sensor.
status_t SMC_SetPowerModeWait(void *arg)
Configures the system to WAIT power mode. API name used from Kinetis family to maintain compatibility...
volatile bool gFxls8962EventReady
void(* pin_init)(pinID_t aPinId, gpio_direction_t dir, void *apPinConfig, gpio_isr_handler_t aIsrHandler, void *apUserData)
GENERIC_DRIVER_GPIO Driver_GPIO_KSDK
union pedometer_t::pedometer_status_tag::@351 status
#define FXLS8962_SDCD_CONFIG2_WT_DBCTM_CLEARED
This structure defines the Read command List.
gpioHandleKSDK_t GREEN_LED
#define FXLS8962_INT_STATUS_SRC_SDCD_OT_MASK
#define FXLS8962_SDCD_CONFIG1_Z_OT_EN_EN
int32_t pedometer_run(pedometer_t *pPedometer, ped_accel_t *pData)
The interface function excutes the pedometer algorithm.
void FXLS8962_I2C_SetIdleTask(fxls8962_i2c_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the I2C Idle Task.
#define FXLS8962_I2C_ADDR
#define FXLS8962_SDCD_CONFIG2_REF_UPDM_SDCD_REF
#define FXLS8962_WHOAMI_VALUE
void pedometer_init(pedometer_t *pPedometer)
The interface function initialize the pedometer.
#define I2C_S_DEVICE_INDEX
void BOARD_InitPins(void)
Configures pin routing and optionally pin electrical features.
#define FXLS8962_INT_EN_ASLP_EN_EN
registerDeviceInfo_t deviceInfo
void fxls8962_int_callback(void *pUserData)
This is the Sensor Event Ready ISR implementation.
#define FXLS8962_SDCD_CONFIG1_Y_OT_EN_EN